#include "node_int.h"
#include <stdlib.h>
typedef struct Stack_Int
{
    Node * top;

}Stack;


Stack* StackCreate() {
    Stack * stack = (Stack*) malloc(sizeof(Stack));
    stack->top =NULL;
    return stack;

}

void StackPush(Stack* obj, int x) 
{
    Node * new_node  = (Node*) malloc(sizeof(Node));
    new_node->elem = x;
    new_node->next =0;
    new_node->last = obj->top;
    if(obj->top)
        obj->top->next = new_node;
    obj->top = new_node;

}

void StackPop(Stack* obj) 
{
    Node * old_Node  = obj->top;
    obj->top = obj->top->last;

    old_Node->last = 0;  //
    if(obj->top)
        obj->top ->next = 0;
    
    free(old_Node) ;

}

Node* StackTop(Stack* obj)
{
    if(obj->top)
    return obj->top;
}

void StackFree(Stack* obj) 
{
    Node * node = obj->top;
    Node * old_node;
    while (node)
    {
        old_node = obj->top->last;
        free(node);
        node = old_node;
    }
    free(obj);
    
}
